<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Db;

/**
 * 后台页面管理
 * @package app\admin\controller
 */
class Index extends AdminBase
{
    public function index()
    {
        return $this->fetch();
    }
    public function home()
    {
        # 展示文章数
        $article_count=model('Article')->getCount();
        $this->assign('article_count', $article_count);
        # 展示登陆数
        $user_count=model('User')->getCount();
        $this->assign('user_count', $user_count);
        # 展示评论数
        $comment_count=model('Comment')->getCount();
        $this->assign('comment_count', $comment_count);
        # 展示留言数
        $message_count=model('Message')->getCount();
        $this->assign('message_count', $message_count);
        # 展示文章
        $article=Db::query("
        SELECT a.*,c.nums 
        FROM ".config('database.prefix')."article a 
        LEFT JOIN (select aid,COUNT(*) nums FROM ".config('database.prefix')."comment WHERE status=0 GROUP BY aid) as c 
        ON a.id=c.aid 
        WHERE a.status=1
        ORDER BY a.update_time DESC 
        LIMIT 3");
        $this->assign('article_list', $article);
        return $this->fetch();
    }
    public function clear()
    {
        shell_exec('php ./../think clear');
        $this->success('清理成功', 'admin/index/index');
    }
}
